package com.springboot.demo.mapper;

import com.springboot.demo.entity.ReaderFine;
import com.springboot.demo.entity.ReaderFineRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 17069120036-汪轶辉-974319097@qq.com
 * @date 2020/4/24
 */
public interface ReaderFineRecordMapper {

    @Select("select readerfinerecord.id , readerfinerecord.bname ,readerfinerecord.start_time, r" +
            "eaderfinerecord.end_time, readerfinerecord.fine  from readerfinerecord  where phone = #{phone} and ispaid = 'unpaid'")
    List<ReaderFineRecord> getReaderFineRecordByPhone(String phonenum);

    @Select("SELECT phone, rname, ID, bname, start_time, end_time, days, fine FROM returntable NATURAL JOIN reader NATURAL JOIN book WHERE phone = #{phone} AND overdue = 'yes'")
    List<ReaderFine> getReaderFineByPhone(String phone);

    /**
     * 插入读者罚金信息
     */
    @Insert("insert into readerFineRecord values(#{phone}, #{rname}, #{bookId}, #{bname}, #{starttime}, #{endtime}, #{fine},'unpaid')")
    void insertReaderFineRecord(String phone, String rname, long bookId, String bname, String starttime, String endtime, int fine);

    /**
     * 读者付钱后修改ispaid为paid
     */
    @Update("update readerFineRecord set ispaid = 'paid' where phone = #{phone} and start_time = #{startTime}" )
    void payReaderFine(String phone, String startTime);


}
